﻿using System;
using System.Collections.Generic;
using System.CodeDom.Compiler;

namespace SWF
{
    public class ConstantPool : IAction, IStackManipulator
    {
        public ActionKind ActionId { get { return ActionKind.ConstantPool; } }
        public uint Version { get { return 5; } }
        public uint Length
        {
            get
            {
                uint len = 5;
                foreach (string s in Constants)
                {
                    len += (uint)s.Length + 1;
                }
                return len;
            }
        }

        public uint StackPops { get { return 0; } }
        public uint StackPushes { get { return 0; } }
        public int StackChange { get { return 0; } }

        public string[] Constants;

        public ConstantPool(SwfReader r)
        {
            uint len = r.GetUI16();

            Constants = new string[len];
            for (int i = 0; i < len; i++)
            {
                Constants[i] = r.GetString();
            }
        }
        // todo: getIndex

        public void Execute(Runtime.Clip clip, Stack<object> stack, Dictionary<string, object> variables, List<string> constantPool, Dictionary<string, List<IAction>> functionmap)
        {
            constantPool.Clear();
            constantPool.AddRange(Constants);
        }
    }
}
